Using Windows COM Objects

Although COM objects can be accessed in Knowledge Builder procedures using the established @OLE2xxx commands, a new and better way has been introduced in Knowledge Builder procedures.

A new (local) Object variable type "O" has been introduced.

e.g. Dim xmlParser : O

A new in-built function (CreateOLEobject) is used to create new objects.

e.g. xmlParser = CreateOLEobject ('Microsoft.XMLDOM')

Direct access to the object's methods and properties using a standard notation

e.g. If xmlParser.Load('c:\temp\test.xml') <> -1

Object instances are automatically destroyed upon exiting the procedure in which they are created, alternatively they can be manually destroyed at any point:

e.g. @Assign xmlParser = UNASSIGNED

An example of a procedure, using this new approach is shown here:

@DIM iFace:o , aNode:o , params:o , aResult:n , aParams:s , c:n , cc:n ,aName:s , aValue:s,n:N
@ASSIGN iFace = CreateOLEobject ('Microsoft.XMLDOM')
@IF iFace.Load('c:\temp\test.xml') <> -1
  @ASSIGN aParams = 'Could not load the file. Probably a bad XML file'
@ELSE
  @ASSIGN aParams = ''
  @FOR c = 0 TO iFace.DocumentElement.childNodes.Length - 1
    @ASSIGN aNode = iFace.DocumentElement.childNodes.item[c]
    @IF aNode.nodeName = 'ATTRIBUTE'
      @ASSIGN params = aNode.attributes
      @ASSIGN aName = ''
      @ASSIGN aValue = ''
      @FOR cc = 0 TO params.Length - 1
        @IF params.item[cc].nodeName = 'NAME'
          @ASSIGN aName = params.item[cc].text
        @ELSE
          @IF params.item[cc].nodeName = 'VALUE'
            @ASSIGN aValue = params.item[cc].text
          @ENDIF
        @ENDIF
      @NEXT
      @IF Length ( aParams ) > 0
        @ASSIGN aParams = aParams + ','
      @ENDIF
      @ASSIGN aParams = aParams + aName + '=' + aValue
      @ASSIGN params = UNASSIGNED
    @ENDIF
    @ASSIGN aNode = UNASSIGNED
  @NEXT
@ENDIF
@ASSIGN iFace = UNASSIGNED